package com.dmwork.service.work.controller.admin;

import com.dmwork.common.base.result.R;
import com.dmwork.service.base.vo.WorkCommonVo;
import com.dmwork.service.work.entity.Work;
import com.dmwork.service.work.service.WorkService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.LinkedList;
import java.util.List;

@Slf4j
@Api(description = "作品服务通用远程调用接口")
@RestController
@RequestMapping("/admin/dm_work/work/feign")
public class AdminWorkFeignController {

    @Autowired
    private WorkService workService;

    @ApiOperation("feign获取作品信息")
    @GetMapping("getWorkInfoByWorkId/{workId}")
    public R<WorkCommonVo> getWorkInfoByWorkId(@PathVariable String workId) {
        Work work = workService.getById(workId);
        WorkCommonVo workCommonVo = new WorkCommonVo()
                .setId(workId)
                .setTitle(work.getTitle())
                .setCover(work.getCover());
        return R.ok("item", workCommonVo);
    }

    @ApiOperation("feign获取作品信息列表")
    @PostMapping("getWorkListByWorkIds")
    public R<List<WorkCommonVo>> getWorkListByWorkIds(@RequestBody List<String> workIdList) {
        List<WorkCommonVo> workCommonVoList=new LinkedList<>();
        List<Work> workList = workService.listByIds(workIdList);
        for (Work work : workList) {
            workCommonVoList.add(new WorkCommonVo().setId(work.getId()).setCover(work.getCover()).setTitle(work.getTitle()));
        }
        return R.ok("rows", workCommonVoList);
    }

}
